<template>
  <div>
    <el-dialog
      v-dialogDrag
      :fullscreen="isFullscreen"
      :visible.sync="dialogVisible"
      :before-close="closeForm"
      width="3rem"
    >
      <div slot="title" class="header-title hd-title">
        <span>{{ dialogTitle }}</span>
        <i
          v-if="isFullscreen === false"
          class="el-icon-full-screen"
          @click="fScreen"
        ></i>

        <i v-else class="el-icon-news" @click="ifScreen"></i>
      </div>
      <el-form :model="form" :rules="rules" ref="form" label-width="80px">
        <el-row v-if="dialogTitle === '国内物流单号'" :gutter="0">
          <el-col :span="24">
            <el-form-item
              style="margin: 20px 0"
              label="国内单号"
              :rules="[
                {
                  required: true,
                  message: '请输入国内单号',
                  trigger: ['blur', 'change'],
                },
              ]"
              prop="waybillNo"
              name="waybillNo"
            >
              <el-input
                placeholder="若多个单号，请回车后再输入输入下一个单号"
                type="textarea"
                v-model="form.waybillNo"
              ></el-input>
            </el-form-item>
          </el-col>
          <div style="text-align: center">
            <span style="color: red">备注：若多个单号，请回车输入下一个</span>
          </div>
        </el-row>
      </el-form>
      <div slot="footer">
        <el-button size="small" type="primary" @click="handleSubmit"
          ><i class="el-icon-circle-plus-outline"></i> 保存
        </el-button>
        <el-button size="small" @click="closeForm"
          ><i class="el-icon-circle-close"></i> 取消
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: {
    editData: {
      type: Object,
      default: () => ({}),
    },
    dialogTitle: {
      type: String,
      default: "",
    },
    dialogVisible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      isFullscreen: false,
      form: {
        waybillNo: [],
      },
      rules: {},
    };
  },
  watch: {
    editData: {
      handler(val) {
        let arr = [];
        let waybillNo = JSON.parse(JSON.stringify(val.waybill));
        waybillNo.forEach((item) => {
          arr.push(item.waybill_No);
        });
        this.form.waybillNo = arr.join("\n");
      },
    },
    dialogTitle: {
      handler(val) {
        if (val === "国内物流单号") {
        }
      },
    },
  },
  methods: {
    handleSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          if (this.dialogTitle === "国内物流单号") {
            const waybillNo = this.form.waybillNo.split("\n");
            let formData = {
              storage_order_id: this.editData.storage_order_id,
              Waybill_No: waybillNo,
            };
            this.$emit("submit", formData);
          }
          this.closeForm();
        }
      });
    },
    closeForm() {
      this.$emit("closeForm");
      this.isFullscreen = false;
      if (this.$refs["form"] !== undefined) {
        this.$refs["form"].resetFields();
      }
    },
    fScreen() {
      this.isFullscreen = true;
    },
    ifScreen() {
      this.isFullscreen = false;
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-checkbox__label {
  color: #a9a9a9;
}

.el-form-item {
  margin-bottom: 0px;
}

::v-deep .el-textarea__inner {
  height: 230px;
}

::v-deep .el-dialog__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #f0f0f0;
}

::v-deep .el-input__inner {
  height: 32px;
  line-height: 32px;
}

::v-deep .el-dialog__body {
  padding: 0 20px;
}

::v-deep .el-dialog__footer {
  padding: 10px 16px;
  border-top: 1px solid #f0f0f0;
}

.el-select-dropdown
  .el-scrollbar
  .el-scrollbar__view
  .el-select-dropdown__item {
  height: auto;
  padding: 0 15px;
}

.hd-title {
  font-size: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex: 1;
  margin-right: 26px;
}

.el-icon-full-screen {
  cursor: pointer;
}

.el-icon-news {
  cursor: pointer;
}
</style>
